package com.roger.tool.net;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;

import com.roger.tool.SGLog;
import com.roger.tool.net.SGHttpTask.SGHttpListener;

public class PayTask {
	
	private static final String URL_ROOT = "";

	private SGHttpTask mSGHttpTask;

	public static PayTask newInstance() {
		return new PayTask();
	}

	public void doRequest(Context context, String orderId, String app_user_id, String pProductId, String amount, String ext) {

		Map<String, String> parames = new HashMap<String, String>();
		parames.put("app_order_id", orderId);
		parames.put("app_user_id", app_user_id);
		parames.put("product_id", pProductId);
		parames.put("amount", amount);
		parames.put("ext", ext);

		// 如果存在，取消上一次请求
//		if (sSdkHttpTask != null) {
//			sSdkHttpTask.cancel(true);
//		}

		// 新请求
		mSGHttpTask = new SGHttpTask(context);
		
		//
		String url = URL_ROOT + "?" + mSGHttpTask.formatParames(parames);
		
		mSGHttpTask.doGet(new SGHttpListener() {

			@Override
			public void onResponse(String response) {

				SGLog.i("onResponse=" + response);

				mSGHttpTask = null;
			}

			@Override
			public void onCancelled() {
				mSGHttpTask = null;
			}

		}, url);

		SGLog.d("Order url=" + url);
	}

	public boolean doCancel() {
		return (mSGHttpTask != null) ? mSGHttpTask.cancel(true) : false;
	}

}
